package com.orm.analysis.dao;

import com.orm.analysis.model.Address;
import com.orm.analysis.model.CustOrder;
import com.orm.analysis.model.Customer;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/10/13
 * Time: 11:55 AM
 * To change this template use File | Settings | File Templates.
 */
public class AddressDAO extends GenericJPADAO<Address, Integer> {
    /**
        * List all the authors order by lastName,firstName ascendent
        *
        * @param page the page number
        * @param size the page size
        * @return a list of authors
        */
       public List<Address> list(int page, int size) {
           Query query = this.em.createQuery("from Address");
           query.setFirstResult((page - 1) * size);
           query.setMaxResults(size);
           return query.getResultList();
       }


       public Address getById(Integer id) {
               return this.em.find(Address.class,id);
       }

       @Transactional
       @Override
       public void save(Address entity) {
            getEntityManager().persist(entity);
       }

    @Transactional
    @Override
    public void saveList(List<Address> entities) {
        for(Address entity: entities){
            getEntityManager().persist(entity);
        }

    }


}
